package util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.aiflow.db.ConnDB;

public class Check {

	public Check(){
		
	}
	
	// 检测 是否重复 
	// 参数col 要检测的列  name 要检测 的内容   talbeName //要检测的表名
	public boolean checkRepeat(String name,String col,String tableName){
		
		boolean bool = false;
		
		String sql = "select count(1) from "+tableName+" where "+col+" = '"+name+"'";
		Connection conn = null;
		PreparedStatement sta = null;
		ResultSet set = null;
		ConnDB db = new ConnDB();
		 conn = db.getConnection();
		 try {   
			sta = conn.prepareStatement(sql);
			
			set = sta.executeQuery();
			set.next();
			int count = set.getInt(1);
			if(count ==0){
				bool = true; 
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			db.closeRs(set);
			db.closeStatement(sta);
			db.closeConnect(conn);
		}
		 
		return bool;
		
	}
	
	
	
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
